package com.yao.mall.controller;

import com.yao.mall.common.ErrorCode;
import com.yao.mall.common.Result;
import com.yao.mall.config.BusinessException;
import com.yao.mall.service.PayService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;



/**
 * @author jiahua.yao
 * @version 1.0
 * @description 支付接口
 * @date 2024/4/7 19:19
 */
@RestController
@RequestMapping("/pay")
@Slf4j
@Tag(name = "支付相关接口")
public class PayController {
    @Resource
    private PayService payService;


    @GetMapping("/aliPay/{orderId}")
    @Operation(summary = "支付宝支付")
    public Result<String> useAliPay(@PathVariable Long orderId){
        String checkout = payService.useAliPay(orderId);
        if(checkout == null){
            throw new BusinessException(ErrorCode.OPERATION_ERROR,"支付发生错误，请稍后再试");
        }
        return Result.success(checkout);
    }

    @PostMapping("/notify")
    @Operation(summary = "支付宝支付回调接口")
    public  String payNotify(HttpServletRequest request)  {
        return payService.payNotify(request);
    }
}
